package org.marsdonne.monitring_agent.activemq

import org.marsdonne.monitring_agent.Reporter
import org.marsdonne.monitring_agent.network.PingMonitor
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.context.annotation.Bean

import javax.annotation.PreDestroy

@SpringBootApplication
class MonitringAgentApplication {

    @Autowired
    JmxMonitor mqMonitor

    @Autowired
    PingMonitor pingMonitor

    @Bean
    @ConfigurationProperties("monitor.activemq.blacklist")
    List<String> blacklist() {
        new ArrayList<String>()
    }

    @Bean
    @ConfigurationProperties("monitor.activemq.whitelist")
    List<String> whitelist() {
        new ArrayList<String>()
    }

    @Bean
    @ConfigurationProperties("reporter.recipients")
    List<String> recipients() {
        new ArrayList<String>()
    }

    @Bean
    Reporter reporter() {
        new Reporter()
    }

    @Bean
    Restarter restarter() {
        new Restarter()
    }

    @Bean
    JmxMonitor mqMonitor(List<String> blacklist, List<String> whitelist, Reporter reporter, Restarter restarter) {
        new JmxMonitor(blacklist: blacklist, whitelist: whitelist, reporter: reporter, restarter: restarter, enabledEmergencyRestart: true)
    }

    @Bean
    @ConfigurationProperties("monitor.ping.hosts")
    List<String> pingHosts() {
        new ArrayList<String>()
    }

    @Bean
    PingMonitor pingMonitor(List<String> pingHosts, Reporter reporter) {
        new PingMonitor(hosts: pingHosts, reporter: reporter)
    }

    @PreDestroy
    void onExit() {
        mqMonitor.stop()
        pingMonitor.stop()
    }

    static void main(String[] args) {
        SpringApplication.run(MonitringAgentApplication, args)
    }

}
